package br.com.fogas.utils;

import java.io.StringWriter;

import org.simpleframework.xml.core.Persister;

import br.com.fogas.utils.exception.ParseXmlException;

public class XmlUtility {

	public String parseXML(Object object) throws ParseXmlException {
		StringWriter writer = new StringWriter();
		Persister persister = new Persister();
		try {
			persister.write(object, writer);
			return writer.toString();
		} catch (Exception e) {
			throw new ParseXmlException("Error parseXML SimpleFramework cause: "+e.getMessage());
		}
	}
	
	public Object unParseXML(Class<? extends Object> clazz, String xml) throws ParseXmlException {
		Persister persister = new Persister();
		try {
			return persister.read(clazz, xml);
		} catch (Exception e) {
			throw new ParseXmlException("Error unParseXML SimpleFramework cause: "+e.getMessage());
		}
	}
}
